package current.security.login.service.impl;

import javax.annotation.Resource;
import current.security.dao.ISecurityDao;
import current.security.login.service.LoginValidateService;
import current.security.login.service.UserInfoService;
import current.security.login.service.UserStateService;
import current.security.user.domain.User;

public abstract class DefaultUserStateServiceImpl implements UserStateService,UserInfoService {
	@Resource(name="loginValidateService") //自动
	LoginValidateService validateService;
	@Resource
	ISecurityDao securityDao ;
    /**
     * hql access database
     * map Paramater key=property value=value
     */
    @Override
	public User queryUserByName(String username) {
		// TODO Auto-generated method stub
    	User user = null;
    	try {
			user = securityDao.queryUserByName(username);
			return user;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
    
    @Override
    public User login(String username, String password) throws Exception {
    	username = username.trim();
    	//根据用户姓名查询用户信息
    	User user = queryUserByName(username);
    	//验证用户名和密码是否正确，返回验证信息
    	String msg = validateService.loginValidate(user, username, password, null);
    	if(msg.equals("OK")){
    		return user;
    	}else{
    		return null;
    	}
    }
    @Override
    public User logout() throws Exception {
    	// TODO Auto-generated method stub
    	return null;
    }

    public LoginValidateService getValidateService() {
		return validateService;
	}

	public void setValidateService(LoginValidateService validateService) {
		this.validateService = validateService;
	}
}
